<template>
    <div v-loading="loading" class="container_user">
        <!-- 左侧导航区域 -->
        <div class="menu">
            <div @click="$router.push({ path: '/' })" class="top">
                <el-icon title="主页">
                    <HomeFilled />
                </el-icon>
                <span> / 会员中心</span>
            </div>
            <el-menu :collapse="isCollapse" :router="true" :default-active="$route.path" class="el-menu-vertical-demo">
                <el-menu-item :index="`/user/certification`">
                    <el-icon>
                        <CreditCard />
                    </el-icon>
                    <template #title><span>实名认证</span></template>
                </el-menu-item>
                <el-menu-item :index="`/user/order`">
                    <el-icon>
                        <DocumentCopy />
                    </el-icon>
                    <template #title><span>挂号订单</span></template>
                </el-menu-item>
                <el-menu-item :index="`/user/patient`">
                    <el-icon>
                        <User />
                    </el-icon>
                    <template #title><span>就诊人管理</span></template>
                </el-menu-item>
                <el-menu-item :index="`/user/profile`">
                    <el-icon>
                        <document />
                    </el-icon>
                    <template #title><span>账号信息</span></template>
                </el-menu-item>
                <el-menu-item :index="`/user/feedback`">
                    <el-icon>
                        <ChatDotRound />
                    </el-icon>
                    <template #title><span>意见反馈</span></template>
                </el-menu-item>
            </el-menu>
        </div>
        <!-- 右侧内容展示区域:路由组件展示位置 -->
        <div class="content">
            <router-view></router-view>
        </div>
    </div>
</template>
  
<script setup lang="ts">
import { ref, onMounted } from 'vue';
import { Document, CreditCard, User, DocumentCopy, ChatDotRound, HomeFilled } from '@element-plus/icons-vue';
import debounce from '@/utils/debounce';
import { useRoute, useRouter } from 'vue-router';
// 获取当前路由的信息
let $route = useRoute()
let $router = useRouter()
let loading = ref<boolean>(true);
let isCollapse = ref(true);

onMounted(async () => {
    hasCollapse();
    loading.value = await false
})

// 判断是否收起菜单栏
const hasCollapse = () => {
    if (window.innerWidth <= 768) {
        isCollapse.value = true
    } else {
        isCollapse.value = false
    }
}
// onresize 监听视口变化
window.addEventListener('resize', debounce(() => {
    hasCollapse()
}, 400));
</script>
<style scoped lang="scss">
.container_user {
    display: flex;

    .menu {
        width: 20%;
        display: flex;
        flex-direction: column;
        align-items: center;

        .top {
            display: flex;
            align-items: center;
            justify-content: center;
            color: black;
            font-weight: 700;
            font-size: 18px;
            margin: 16px 0;
            white-space: nowrap;
            cursor: pointer;

            span {
                margin-left: 10px;
            }
        }

        .top:hover {
            color: #7f7f7f;
        }

        .el-menu {
            min-height: 100vh;
            height: 100%;
        }
    }

    .content {
        width: 80%;
        padding: 72px 0 16px;
    }
}

@media (max-width:768px) {
    .menu {
        .top {
            font-size: 16px;

            span {
                display: none;
            }
        }

        .el-menu {
            min-height: 100vh !important;
        }
    }

    .container_user {
        .content {
            padding: 72px 16px 16px !important;
        }
    }
}
</style>
  